package com.ict.txmsv2.controller.system;

import com.ict.txmsv2.model.Menu;
import com.ict.txmsv2.model.MethodDescrition;
import com.ict.txmsv2.model.RespBean;
import com.ict.txmsv2.services.MenuRoleService;
import com.ict.txmsv2.services.MenuService;
import com.ict.txmsv2.services.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author linzzz
 * @desc ...
 * @date 2020-12-17
 */
@RestController
@RequestMapping("/system/permiss")
public class SystemPermisController {
    @Autowired
    RoleService roleService;

    @Autowired
    MenuRoleService menuRoleService;

    @Autowired
    MenuService menuService;

    @GetMapping("/")
    @MethodDescrition("获取所有菜单")
    public List<Menu> getAllMenu(){
        return menuService.getAllMenus();
    }

    @MethodDescrition("查询角色菜单绑定")
    @GetMapping("/{rid}")
    public Integer[] getMidsByRid(@PathVariable Integer rid){
        return roleService.getMidsByRid(rid);
    }

    @MethodDescrition("更新角色菜单绑定")
    @PutMapping("/")
    public RespBean updateMenuRoles(Integer rid, Integer[] mids){
        if (menuRoleService.updateMenuRoles(rid,mids)){
            return RespBean.ok("更新成功");
        }
        return RespBean.error("更新失败");
    }
}
